Ext.define('Seq.exporter.excel.Xlsx', {
    override: 'Ext.exporter.excel.Xlsx',

    buildRows: function (group, colMerge, level) {
        var me = this,
            showSummary = me._showSummary,
            rows = [],
            groups, row, styleH, styleF, cells,
            i, j, k, gLen, sLen, cLen, oneLine,
            text, items, cell, temp, style;

        if (!group) {
            return rows;
        }

        groups = group._groups;
        text = group._text;

        // if the group has no subgroups and no rows then show only summaries
        oneLine = (!groups && !group._rows);

        if (showSummary !== false && !Ext.isEmpty(text) && !oneLine) {
            styleH = me.getGroupHeaderStyleByLevel(level);
            rows.push({
                styleId: styleH,
                cells: [{
                    mergeAcross: colMerge - 1,
                    value: text,
                    styleId: styleH
                }]
            });
        }

        if (groups) {
            gLen = groups.length;
            for (i = 0; i < gLen; i++) {
                Ext.Array.insert(rows, rows.length, me.buildRows(groups.items[i], colMerge, level + 1));
            }
        }
        if (group._rows) {
            items = group._rows.items;
            sLen = items.length;
            for (k = 0; k < sLen; k++) {
                temp = items[k];
                row = {
                    id: temp._id,
                    cells: []
                };
                cells = temp._cells;
                cLen = cells.length;
                for (j = 0; j < cLen; j++) {
                    cell = cells.items[j];
                    style = me.columnStylesNormalId[j];
                    row.cells.push({
                        id: cell._id,
                        value: Ext.isObject(cell._value) ? cell._value.name : cell._value, // TODO 数据是对象
                        styleId: me.getCellStyleId(cell._style, style)
                    });
                }
                rows.push(row);
            }
        }

        items = group._summaries && group._summaries.items;
        if (items && (showSummary || oneLine)) {
            styleF = me.getGroupFooterStyleByLevel(level);
            sLen = items.length;
            for (k = 0; k < sLen; k++) {
                // that's the summary footer
                temp = items[k];
                row = {
                    id: temp._id,
                    cells: []
                };
                cells = temp._cells;
                cLen = cells.length;
                for (j = 0; j < cLen; j++) {
                    cell = cells.items[j];
                    style = oneLine ? me.columnStylesNormalId[j] : (j === 0 ? styleF : me.columnStylesFooterId[j]);
                    row.cells.push({
                        id: cell._id,
                        value: Ext.isObject(cell._value) ? cell._value.name : cell._value, // TODO 数据是对象
                        styleId: me.getCellStyleId(cell._style, style)
                    });
                }
                rows.push(row);
            }
        }
        group.destroy();

        return rows;
    }

});